package com.base.recycleView.ViewModel;

import com.base.mvvm2.BasePresenterImpl2;
import com.base.recycleView.adapter.BaseReceycleAdapter;
import com.face.gaoml.netlibrary.data.rusult.BaseSubscriber;
import com.face.gaoml.netlibrary.data.rusult.HttpResultFunc;
import com.face.gaoml.netlibrary.widget.MsgAlert;

import java.util.ArrayList;

import javax.inject.Inject;

import rx.Observable;

/**
 * Created by gml on 17/1/6.
 */

public abstract class BaseRecycleViewModle<T, A extends BaseReceycleAdapter<T>> extends BasePresenterImpl2 {


    private A mAdapter;

      //1 构造函数 提供支援 提供对象     2.注入构造器所需要的参数的依赖 （ 注入传递）
    public BaseRecycleViewModle(A tSimpleAdapter) {
        this.mAdapter = tSimpleAdapter;
    }


    public void findall() {
        mRxManager.addSubscription(
                getDataURL()
                        .map(new HttpResultFunc<ArrayList<T>>()),
                new BaseSubscriber<ArrayList<T>>() {
                    @Override
                    public void onNext(ArrayList<T> result) {
                        if (result != null) {
                            mAdapter.addAll(result);
                            new MsgAlert().show(result.toString());
                        }
                    }
                }

        );
    }

    public A gettSimpleAdapter() {
        return mAdapter;
    }

    // 子类实现此方法

   public abstract Observable getDataURL();

}
